const { mockAPI } = require('../../../utils/mockData');

Page({
  data: {
    order: null,
    loading: true
  },
  onLoad(options) {
    const id = options.id;
    this.loadDetail(id);
  },
  loadDetail(id) {
    this.setData({ loading: true });
    mockAPI.getOrderDetail(id).then(res => {
      this.setData({ order: res.data, loading: false });
    });
  },
  onPay() {
    const id = this.data.order.orderId;
    mockAPI.payOrder({ orderId: id, paymentType: '微信' }).then(() => {
      wx.showToast({ title: '支付成功', icon: 'success' });
      this.loadDetail(id);
    });
  },
  onCancel() {
    const id = this.data.order.orderId;
    wx.showModal({
      title: '提示',
      content: '确定要取消该订单吗？',
      success: (res) => {
        if (res.confirm) {
          mockAPI.cancelOrder(id).then(() => {
            wx.showToast({ title: '已取消', icon: 'success' });
            this.loadDetail(id);
          });
        }
      }
    });
  },
  onComplete() {
    const id = this.data.order.orderId;
    wx.showModal({
      title: '确认完成',
      content: '请确认服务已完成',
      success: (res) => {
        if (res.confirm) {
          mockAPI.completeOrder(id).then(() => {
            wx.showToast({ title: '已完成', icon: 'success' });
            this.loadDetail(id);
          });
        }
      }
    });
  },
  onComment() {
    const id = this.data.order.orderId;
    wx.navigateTo({ url: '/pages/my/orderComment/orderComment?id=' + id });
  }
}); 